<?php

namespace app\api\controller;

use app\common\controller\Api;

/**
 * 示例接口
 */
class Master extends Api
{

    //如果$noNeedLogin为空表示所有接口都需要登录才能请求
    //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
    //如果接口已经设置无需登录,那也就无需鉴权了
    //
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = [''];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];

    /**
     * 工头发布招工信息
     */
    public function sendzhaomsg(){
        //用户id
        $user = $this->auth->getUserinfo();
        $user_id=$user['id'];
        //获取用户信息 判断是否是工头
        $user = db('user')->where(['id'=>$user_id])->find();
        if($user['type']!=2){
            $this->error('不可发布招工');
        }
        //id 判断修改还是增加
        $id = input('work_id');
        //接收提交人数信息
        $jgg_db_num = input('jgg_db_num')?input('jgg_db_num'):0;
        $jgg_dg_num = input('jgg_dg_num')?input('jgg_dg_num'):0;
        $jgg_zg_num = input('jgg_zg_num')?input('jgg_zg_num'):0;
        $jgg_xg_num = input('jgg_xg_num')?input('jgg_xg_num'):0;
        $fgg_db_num = input('fgg_db_num')?input('fgg_db_num'):0;
        $fgg_dg_num = input('fgg_dg_num')?input('fgg_dg_num'):0;
        $fgg_zg_num = input('fgg_zg_num')?input('fgg_zg_num'):0;
        $fgg_xg_num = input('fgg_xg_num')?input('fgg_xg_num'):0;
        $dg_db_num = input('dg_db_num')?input('dg_db_num'):0;
        $dg_dg_num = input('dg_dg_num')?input('dg_dg_num'):0;
        $dg_zg_num = input('dg_zg_num')?input('dg_zg_num'):0;
        $dg_xg_num = input('dg_xg_num')?input('dg_xg_num'):0;
        $cs_db_num = input('cs_db_num')?input('cs_db_num'):0;
        $cs_dg_num = input('cs_dg_num')?input('cs_dg_num'):0;
        $cs_zg_num = input('cs_zg_num')?input('cs_zg_num'):0;
        $cs_xg_num = input('cs_xg_num')?input('cs_xg_num'):0;
        $title = input('title')?input('title'):'';
        $status = input('status')?input('status'):1;
        if($jgg_db_num<0 || $jgg_dg_num<0 ||$jgg_zg_num<0 ||$jgg_xg_num<0 ||$fgg_db_num<0 ||$fgg_dg_num<0 ||$fgg_zg_num<0 ||$fgg_xg_num<0 ||$dg_db_num<0 ||$dg_dg_num<0 ||$dg_zg_num<0 ||$dg_xg_num<0 ||$cs_db_num<0 ||$cs_dg_num<0 ||$cs_zg_num<0 ||$cs_xg_num<0){
            $this->error('人数不能小于0');
        }
        if(!$title){
            $this->error('招工标题不能空');
        }
        //接收地址信息
        $address = input('address')?input('address'):'';
        if(!$address){
            $this->error('工作地方不能空');
        }
        //工作大约用时
        $work_time = input('work_time')?input('work_time'):0;
        $data['user_id'] = $user_id;
        $data['jgg_db_num'] = $jgg_db_num;
        $data['jgg_dg_num'] = $jgg_dg_num;
        $data['jgg_zg_num'] = $jgg_zg_num;
        $data['jgg_xg_num'] = $jgg_xg_num;
        $data['fgg_db_num'] = $fgg_db_num;
        $data['fgg_dg_num'] = $fgg_dg_num;
        $data['fgg_zg_num'] = $fgg_zg_num;
        $data['fgg_xg_num'] = $fgg_xg_num;
        $data['dg_db_num'] = $dg_db_num;
        $data['dg_dg_num'] = $dg_dg_num;
        $data['dg_zg_num'] = $dg_zg_num;
        $data['dg_xg_num'] = $dg_xg_num;
        $data['cs_db_num'] = $cs_db_num;
        $data['cs_dg_num'] = $cs_dg_num;
        $data['cs_zg_num'] = $cs_zg_num;
        $data['cs_xg_num'] = $cs_xg_num;
        $data['address'] = $address;
        $data['title'] = $title;
        $data['work_time'] = $work_time;
        $data['status'] = $status;
        
        if($id){
            //修改
            $r = db('work')->where(['id'=>$id])->update($data);
        }else{
            $data['createtime'] = time();
            $r = db('work')->insert($data);
        }
        
         $this->success('操作成功');
       
        
    }
    /**
     * 招工启事
     */
    public function zhaogongdetail(){
        $user = $this->auth->getUserinfo();
        $user_id=$user['id'];
        $id = input('id');
        if(empty($id)){
            $this->error('参数错误');
        }
        $list = db('work')->where(['id'=>$id])->find();
        if(empty($list)){
            $this->error('参数错误');
        }
        $list['createtime'] = date('Y-m-d H:i:s',$list['createtime']);
        $user = db('user')->where(['id'=>$list['user_id']])->find();
        $list['username'] = $user['username'];
        $list['mobile'] = $user['mobile'];
        //判断有没有被收藏
        $check = db('collection')->where(['user_id'=>$user_id,'work_id'=>$id])->find();
        if($check){
            $list['is_collect'] = 1;
        }else{
            $list['is_collect'] = 2;
        }
        $this->success('查询成功',$list);
    }
    /**
     * 工人发起申请
     */
    public function workerplease(){
        $user = $this->auth->getUserinfo();
        $user_id=$user['id'];
        $boss_id = input('boss_id')?input('boss_id'):'';
        $work_id = input('work_id')?input('work_id'):'';
        if(empty($boss_id) || empty($work_id)){
            $this->error('参数错误');
        }
        //去重复
        $check = db('findwork')->where(['work_id'=>$work_id,'worker_id'=>$user_id,'user_id'=>$boss_id,'status'=>1])->find();
        if($check){
            $this->error('请勿重复申请');
        }
        //工人级别 工种
        $newuser=db('User')->where(['id'=>$worker_id])->find();
        if($newuser){
            $data['work']=$newuser['work'];
            $data['level']=$newuser['level'];
        }
        $data['user_id'] = $boss_id;
        $data['work_id'] = $work_id;
        $data['worker_id'] = $user_id;
        $data['createtime'] = time();
        $data['status'] = 1;
        $data['type'] = 1;
        $r = db('findwork')->insert($data);
        if($r){
            $this->success('申请成功');
        }else{
            $this->error('申请失败');
        }
    }
    /**
     * 老板向工人发起申请
     */
    public function findworker(){
        $user = $this->auth->getUserinfo();
        $user_id=$user['id'];
        $worker_id = input('worker_id')?input('worker_id'):'';
        $work_id = input('work_id')?input('work_id'):'';
        $money = input('money')?input('money'):'';
        if(empty($money)){
            $this->error('日工资不能空');
        }
        if(empty($worker_id) || empty($work_id)){
            $this->error('参数错误');
        }
        //去重复
        $check = db('findwork')->where(['work_id'=>$work_id,'worker_id'=>$worker_id,'user_id'=>$user_id,'status'=>1])->find();
        if($check){
            $this->error('请勿重复申请');
        }
        //工人级别 工种
        $newuser=db('User')->where(['id'=>$worker_id])->find();
        if($newuser){
            $data['work']=$newuser['work'];
            $data['level']=$newuser['level'];
        }
        $data['user_id'] = $user_id;
        $data['work_id'] = $work_id;
        $data['worker_id'] = $worker_id;
        $data['createtime'] = time();
        $data['status'] = 1;
        $data['type'] = 2;
        $data['money'] = $money;
        $r = db('findwork')->insert($data);
        if($r){
            $this->success('申请成功');
        }else{
            $this->error('申请失败');
        }

    }
    /**
     * 未确认 进行中的 已完成列表
     */
    public function confirmelist(){
        $user = $this->auth->getUserinfo();
        $user_id=$user['id'];
        $page = input('page')?input('page'):1;
        $limit = input('limit')?input('limit'):10;
        $state = input('state')?input('state'):1;
        $user = db('user')->where(['id'=>$user_id])->find();
        if($user['type']==1){
            //工人
            $list = db('findwork')->where(['worker_id'=>$user_id,'state'=>$state])->page($page,$limit)->select();
            //查找工作的信息
            foreach($list as $k=>$v){
                //工人工时,加班时长
                $status= db('worker_perform')->field('status,add_day')->where(['work_id'=>$v['work_id'],'user_id'=>$user_id])->sum('status');
                $add_day= db('worker_perform')->field('status,add_day')->where(['work_id'=>$v['work_id'],'user_id'=>$user_id])->sum('add_day');
                $list[$k]['status'] = $status/2;
                $list[$k]['add_day'] = $add_day/2;
                $work = db('work')->field('title,address')->where(['id'=>$v['work_id']])->find();
                //工头的信息
                $boss = db('user')->field('username,mobile')->where(['id'=>$v['user_id']])->find();
                $boss['phone'] = $boss['mobile'];
                $list[$k]['mesg'] = $boss;
                //申请的工种
                if($user['work']==1){
                    $list[$k]['workz'] = '结构工';
                }elseif($user['work']==2){
                    $list[$k]['workz'] = '管道工';
                }elseif($user['work']==3){
                    $list[$k]['workz'] = '纯水工';
                }else{
                    $list[$k]['workz'] = '电工';
                }
                //工人的级别
                if($user['level']==1){
                    $list[$k]['level'] = '小工';
                }elseif($user['level']==2){
                    $list[$k]['level'] = '中工';
                }elseif($user['level']==3){
                    $list[$k]['level'] = '大工';
                }else{
                    $list[$k]['level'] = '带班';
                }
                $list[$k]['work'] = $work;
                //是否有按钮
                if($v['type']==1){
                    $list[$k]['btn'] = 1;//无按钮
                }else{
                    $list[$k]['btn'] = 2;//有按钮
                }
                
            }
        }else{
            //工头
            $list = db('findwork')->where(['user_id'=>$user_id,'state'=>$state])->page($page,$limit)->select();
            //查找工作的信息
            foreach($list as $k=>$v){
                //工人工时,加班时长
                $status= db('boss_perform')->field('status,add_day')->where(['work_id'=>$v['work_id'],'worker_id'=>$v['worker_id'],'user_id'=>$user_id])->sum('status');
                $add_day= db('boss_perform')->field('status,add_day')->where(['work_id'=>$v['work_id'],'worker_id'=>$v['worker_id'],'user_id'=>$user_id])->sum('add_day');
                $list[$k]['status'] = $status/2;
                $list[$k]['add_day'] = $add_day/2;
                $work = db('work')->field('title,address')->where(['id'=>$v['work_id']])->find();
                $user = db('user')->field('username,phone,work,level')->where(['id'=>$v['worker_id']])->find();
                $list[$k]['mesg'] = $user;
                $list[$k]['work'] = $work;
                //申请的工种
                if($user['work']==1){
                    $list[$k]['workz'] = '结构工';
                }elseif($user['work']==2){
                    $list[$k]['workz'] = '管道工';
                }elseif($user['work']==3){
                    $list[$k]['workz'] = '纯水工';
                }else{
                    $list[$k]['workz'] = '电工';
                }
                //工人的级别
                if($user['level']==1){
                    $list[$k]['level'] = '小工';
                }elseif($user['level']==2){
                    $list[$k]['level'] = '中工';
                }elseif($user['level']==3){
                    $list[$k]['level'] = '大工';
                }else{
                    $list[$k]['level'] = '带班';
                }
                //是否有按钮
                if($v['type']==2){
                    $list[$k]['btn'] = 1;//无按钮
                }else{
                    $list[$k]['btn'] = 2;//有按钮
                }
            }
        }
        $this->success('查询成功',$list);
    }
    /**
     * 点击接受邀请
     */
    public function accessplease(){
        $user = $this->auth->getUserinfo();
        $user_id=$user['id'];
        $findwork_id = input('findwork_id')?input('findwork_id'):'';
        
        if(empty($findwork_id)){
            $this->error('参数错误');
        }
        $user = db('user')->where(['id'=>$user_id])->find();
       // var_dump($user);
        if($user['type']==1){
            //工人
            $list = db('findwork')->where(['id'=>$findwork_id])->find();
            //查找工作的信息
            if($list['type']==2){
                db('findwork')->where(['id'=>$findwork_id])->update(['status'=>2,'state'=>2,'maketime'=>time()]);
                $this->success('操作成功');
            }else{
                $this->error('参数错误');
            }
        }else{
            //工头
            $money = input('money')?input('money'):'';
            if(empty($money)){
                $this->error('日工资不能空');
            }
            $list = db('findwork')->where(['id'=>$findwork_id])->find();
            //查找工作的信息
            if($list['type']==1){
                db('findwork')->where(['id'=>$findwork_id])->update(['status'=>2,'state'=>2,'maketime'=>time(),'money'=>$money]);
                $this->success('操作成功');
            }else{
                $this->error('参数错误');
            }
        }
    }
    /**
     * 点击拒绝邀请
     */
    public function refuseplease(){
        $user = $this->auth->getUserinfo();
        $user_id=$user['id'];
        $findwork_id = input('findwork_id')?input('findwork_id'):'';
        if(empty($findwork_id)){
            $this->error('参数错误');
        }
        $user = db('user')->where(['id'=>$user_id])->find();
       // var_dump($user);
        if($user['type']==1){
            //工人
            $list = db('findwork')->where(['id'=>$findwork_id])->find();
            //查找工作的信息
            if($list['type']==2){
                db('findwork')->where(['id'=>$findwork_id])->update(['status'=>3]);
                $this->success('操作成功');
            }else{
                $this->error('参数错误');
            }
        }else{
            //工头
            $list = db('findwork')->where(['id'=>$findwork_id])->find();
            //查找工作的信息
            if($list['type']==1){
                db('findwork')->where(['id'=>$findwork_id])->update(['status'=>3]);
                $this->success('操作成功');
            }else{
                $this->error('参数错误');
            }
        }
    }
    /**
     * 工头点击完成
     */
    public function setcompet(){
        $user = $this->auth->getUserinfo();
        $user_id=$user['id'];
        $findwork_id = input('findwork_id')?input('findwork_id'):'';
        if(empty($findwork_id)){
            $this->error('参数错误');
        }
        $list = db('findwork')->where(['user_id'=>$user_id,'id'=>$findwork_id])->find();
        if($list){
            //更改状态
            $data['state'] = 3;
            db('findwork')->where(['id'=>$findwork_id])->update($data);
        }else{
            $this->error('参数错误');
        }
        $this->success('操作成功');
    }

    /****************************************************记工*****************************************/

    /**
     * 工人记工
     */
    public function workerperform(){
        $user = $this->auth->getUserinfo();
        $user_id=$user['id'];
        $work_id = input('work_id')?input('work_id'):'';
        if(!$work_id){
            $this->error('请选择工作');
        }
        //记工日期
        $perform_time = input('perform_time')?input('perform_time'):'';//2019-10-1
        if(!$perform_time){
            $this->error('请选择记工日期');
        }
        //工作时长
        $status = input('status');
        // if($status==''){
        //     $this->error('请选择工作时长');
        // }
        //是否加班
        $add_status = input('add_status')?input('add_status'):'';
        if(empty($add_status)){
            $this->error('请选择加班状态');
        }
        //加班时长
         $add_day = input('add_day');
        // if($add_day==''){
        //     $this->error('请选择加班时长');
        // }
        $findwork = db('findwork')->where(['worker_id'=>$user_id,'work_id'=>$work_id])->find();
        //判断今日是否已有记录
        $check = db('worker_perform')->where(['user_id'=>$user_id,'work_id'=>$work_id,'perform_time'=>strtotime($perform_time)])->find();
        if($check){
            $this->error('今日已记工');
        }
        $data['money'] = $findwork['money']*($add_day+$status)/2;
        $data['work_id'] = $work_id;
        $data['user_id'] = $user_id;
        $data['perform_time'] = strtotime($perform_time);
        $data['status'] = $status;
        $data['add_status'] = $add_status;
        $data['add_day'] = $add_day;
        $data['createtime'] = time();
        db('worker_perform')->insert($data);
        $this->success('记录成功');
    }
    /**
     * 老板记工
     */
    public function bossperform(){
        $user = $this->auth->getUserinfo();
        $user_id=$user['id'];
        $work_id = input('work_id')?input('work_id'):'';
        if(!$work_id){
            $this->error('请选择工作');
        }
        //工人id
        $worker_id = input('worker_id')?input('worker_id'):'';
        if(!$worker_id){
            $this->error('请选择工人');
        }
        $worker = db('user')->field('username')->where(['id'=>$worker_id])->find();
        if(empty($worker)){
            $this->error('工人不存在');
        }
        //记工日期
        $perform_time = input('perform_time')?input('perform_time'):'';//2019-10-1
        if(!$perform_time){
            $this->error('请选择记工日期');
        }
        //工作时长
         $status = input('status');
        // if($status==''){
        //     $this->error('请选择工作时长');
        // }
        //是否加班
        $add_status = input('add_status')?input('add_status'):'';
        if(empty($add_status)){
            $this->error('请选择加班状态');
        }
        //加班时长
        $add_day = input('add_day');
        // if($add_day==''){
        //     $this->error('请选择加班时长');
        // }
        //判断今日是否已有记录
        $check = db('boss_perform')->where(['user_id'=>$user_id,'worker_id'=>$worker_id,'work_id'=>$work_id,'perform_time'=>strtotime($perform_time)])->find();
        if($check){
            $this->error('今日已记工');
        }
        $findwork = db('findwork')->where(['worker_id'=>$worker_id,'work_id'=>$work_id])->find();
        $data['money'] = $findwork['money']*($add_day+$status)/2;
        $data['user_id'] = $user_id;
        $data['work_id'] = $work_id;
        $data['worker_id'] = $worker_id;
        $data['worker_name'] = $worker['username'];
        $data['perform_time'] = strtotime($perform_time);
        $data['status'] = $status;
        $data['add_status'] = $add_status;
        $data['add_day'] = $add_day;
        $data['createtime'] = time();
        db('boss_perform')->insert($data);
        $this->success('记录成功');
    }
    /**
     * 工人工作列表
     */
    public function workerworklist(){
        $user = $this->auth->getUserinfo();
        $user_id=$user['id'];
        $list = db('findwork')->field('work_id')->where(['worker_id'=>$user_id,'state'=>2,'status'=>2])->select();
        foreach($list as $k=>$v){
            $work = db('work')->where(['id'=>$v['work_id']])->find();
            $list[$k]['title'] = $work['title'];
            $list[$k]['id'] = $work['id'];
        }
        $this->success('查询成功',$list);
    }
    /**
     * boss-工作列表
     */
    public function bossworklist(){
        $user = $this->auth->getUserinfo();
        $user_id=$user['id'];
        $list = db('work')->field('id,title')->where(['user_id'=>$user_id])->select();
        $this->success('查询成功',$list);
    }
    /**
     * boss-员工列表
     */
    public function getworkerlist(){
        $page = input('page')?input('page'):1;
        $limit = input('limit')?input('limit'):10;
        $user = $this->auth->getUserinfo();
        $user_id=$user['id'];
        $boss = db('user')->where(['id'=>$user_id,'type'=>2])->find();
        if(empty($boss)){
            $this->error('参数错误');
        }
        //记工日期
        $perform_time = input('perform_time')?input('perform_time'):'';//2019-10-1
        if(!$perform_time){
            $this->error('请选择记工日期');
        }
        //工作id
        $work_id = input('work_id')?input('work_id'):'';
        if(!$work_id){
            $this->error('请选择工作');
        }
        //工作id
        $where['user_id'] = $user_id;
        $where['work_id'] = $work_id;
        $where['status'] = 2;
        // $where['endtime'] = ['>=',$perform_time];
        $list = db('findwork')->where($where)->page($page,$limit)->select();
        if($list){
            foreach($list as $k=>$v){
                //工人信息
                $worker = db('user')->where(['id'=>$v['worker_id']])->find();
                $list[$k]['username'] = $worker['username'];
                if($worker['work']==1){
                    $list[$k]['work'] = '结构';
                }elseif($worker['work']==2){
                    $list[$k]['work'] = '管道';
                }elseif($worker['work']==3){
                    $list[$k]['work'] = '纯水';
                }elseif($worker['work']==4){
                    $list[$k]['work'] = '电工';
                }
                //项目信息
                $workmsg = db('work')->where(['id'=>$v['work_id']])->find();
                $list[$k]['title'] = $workmsg['title'];
                $perform = db('boss_perform')->where(['user_id'=>$user_id,'worker_id'=>$v['worker_id'],'perform_time'=>strtotime($perform_time),'work_id'=>$v['work_id']])->find();
                if($perform){
                    $list[$k]['perform_status'] = 1;//已经记录
                    $list[$k]['perform_day'] = $perform['status'];
                    $list[$k]['perform_add'] = $perform['add_day'];
                }else{
                    $list[$k]['perform_status'] = 2;//还未记录
                    $list[$k]['perform_day'] = '';
                    $list[$k]['perform_add'] = '';
                }
            }
        }
        $this->success('查询成功',$list);
    }
    /**
     * 工人的记工页面
     */
    public function getmylist(){
        $user = $this->auth->getUserinfo();
        $user_id=$user['id'];
        //记工日期
        $perform_time = input('perform_time')?input('perform_time'):'';//2019-10-1
        if(!$perform_time){
            $this->error('请选择记工日期');
        }
        //工作id
        $work_id = input('work_id')?input('work_id'):'';
        if(!$work_id){
            $this->error('请选择工作');
        }

        $where['worker_id'] = $user_id;
        $where['work_id'] = $work_id;
        $where['status'] = 2;
        //$where['endtime'] = ['>=',$perform_time];
        $list = db('findwork')->where($where)->find();
        if(!$list){
            $this->error('参数错误');
        }
        //工人信息
        $worker = db('user')->where(['id'=>$user_id])->find();
        $list['username'] = $worker['username'];
        if($worker['work']==1){
            $list['work'] = '结构';
        }elseif($worker['work']==2){
            $list['work'] = '管道';
        }elseif($worker['work']==3){
            $list['work'] = '纯水';
        }elseif($worker['work']==4){
            $list['work'] = '电工';
        }
        //项目信息
        $workmsg = db('work')->where(['id'=>$list['work_id']])->find();
        $list['title'] = $workmsg['title'];
        if($list){
            $perform = db('worker_perform')->where(['user_id'=>$user_id,'perform_time'=>strtotime($perform_time),'work_id'=>$work_id])->find();
            //var_dump($perform);die;
            if($perform){
                $list['perform_status'] = 1;//已经记录
                $list['perform_day'] = $perform['status'];
                $list['perform_add'] = $perform['add_day'];
            }else{
                $list['perform_status'] = 2;//还未记录
                $list['perform_day'] = '';
                $list['perform_add'] = '';
            }
            
            $this->success('查询成功',$list);
        }else{
            $this->error('今日暂无该工作');
        }
    }
    /**
     * 工人重新记录
     */
    public function workerrefresh(){
        $user = $this->auth->getUserinfo();
        $user_id=$user['id'];
        //记工日期
        $perform_time = input('perform_time')?input('perform_time'):'';//2019-10-1
        if(!$perform_time){
            $this->error('请选择记工日期');
        }
        //工作id
        $work_id = input('work_id')?input('work_id'):'';
        if(!$work_id){
            $this->error('请选择工作');
        }
        $where['user_id'] = $user_id;
        $where['work_id'] = $work_id;
        $where['perform_time'] = strtotime($perform_time);
        $r = db('worker_perform')->where($where)->delete();
        if($r){
            $this->success('操作成功');
        }else{
            $this->error('操作失败');
        }
    }
    /**
     * boss-重新记录工人
     */
    public function bossrefresh(){
        $user = $this->auth->getUserinfo();
        $user_id=$user['id'];
        //记工日期
        $perform_time = input('perform_time')?input('perform_time'):'';//2019-10-1
        if(!$perform_time){
            $this->error('请选择记工日期');
        }
        //工作id
        $work_id = input('work_id')?input('work_id'):'';
        if(!$work_id){
            $this->error('请选择工作');
        }
        //工人id
        $worker_id = input('worker_id')?input('worker_id'):'';
        if(!$worker_id){
            $this->error('请选择工人');
        }
        $worker = db('user')->field('username')->where(['id'=>$worker_id])->find();
        if(empty($worker)){
            $this->error('工人不存在');
        }
        $where['user_id'] = $user_id;
        $where['work_id'] = $work_id;
        $where['worker_id'] = $worker_id;
        $where['perform_time'] = strtotime($perform_time);
        $r = db('boss_perform')->where($where)->delete();
        if($r){
            $this->success('操作成功');
        }else{
            $this->error('操作失败');
        }
    }
    /**
     * 工人日历页面
     */
    public function workercalendar(){
        $user = $this->auth->getUserinfo();
        $user_id=$user['id'];
        //开始日期
        $start_time = input('start_time')?input('start_time'):'';
        if(!$start_time){
            $this->error('请选择开始日期');
        }
        $time = date('t',strtotime($start_time.'-1'));
        //结束日期
        $end_time = $start_time.'-'.$time;
        
        //找到当前的一个工作
        $work_id = input('work_id');
        if($work_id){
            $work['work_id'] = $work_id;
        }else{
            $where['worker_id'] = $user_id;
            $where['state'] = 2;
            $work = db('findwork')->where($where)->find();
        }
        
        //查看这个工作的记工状态
        $where = [];
        $where['user_id'] = $user_id;
        $where['work_id'] = $work['work_id'];
        $where['perform_time'] = ['between time',[$start_time,$end_time]];
        $list = db('worker_perform')->field('perform_time,status')->where($where)->select();
        foreach($list as $k=>$v){
            $list[$k]['perform_time'] = date('Y-m-d',$v['perform_time']);
        }
        $worklist = db('findwork')->field('work_id')->where(['worker_id'=>$user_id,'state'=>2,'status'=>2])->select();
        foreach($worklist as $k=>$v){
            $work = db('work')->where(['id'=>$v['work_id']])->find();
            $worklist[$k]['title'] = $work['title'];
            $worklist[$k]['id'] = $work['id'];
        }
        $data['list'] = $list;
        $data['worklist'] = $worklist;
        $this->success('操作成功',$data);
    }
    /**
     * boss-日历页面
     */
    public function bosscalendar(){
        $user = $this->auth->getUserinfo();
        $user_id=$user['id'];
        //开始日期
        //开始日期
        $start_time = input('start_time')?input('start_time'):'';
        if(!$start_time){
            $this->error('请选择开始日期');
        }
        $time = date('t',strtotime($start_time.'-1'));
        //结束日期
        $end_time = $start_time.'-'.$time;
        $work_id = input('work_id');
        
        $worklist = db('work')->field('id,title')->where(['user_id'=>$user_id,'status'=>1])->select();
        
        $data['worklist'] = $worklist;
        if(empty($worklist)){
            $list['worker_num'] = 0;
            $list['worker_money'] = 0;
        }else{
            if($work_id){
           
            }else{
               $work_id = $worklist[0]['id'];
            }
            $where['perform_time'] = ['between time',[$start_time,$end_time]];
            $list['worker_num'] = db('findwork')->where(['user_id'=>$user_id,'work_id'=>$work_id,'state'=>2])->count();
            $list['worker_money'] = db('boss_perform')->where(['user_id'=>$user_id,'work_id'=>$work_id])->where($where)->sum('money');
        }
        $data['list'] = $list;
        $this->success('查询成功',$data);
    }
    /**
     * 修改工作信息页面
     */
    public function editwork(){
        $user = $this->auth->getUserinfo();
        $user_id=$user['id'];
        $work_id = input('work_id');
        if(empty($work_id)){
            $this->error('参数错误');
        }
        $work = db('work')->where(['id'=>$work_id])->find();
        $this->success('查询成功',$work);
    }
    /**
     * 工作协议
     */
    public function xieyi(){
        $xieyi = Config('site.xieyi');
        $this->success('查询成功',$xieyi);
    }
    
}
